class Solution {
    public int maxSubArray(int[] nums) {
        int max = nums[0];
        int curr= nums[0];
        for (int i=1;i<nums.length;i++){
            if (nums[i]>curr+nums[i]){
                curr=nums[i];
            }else {
                curr = curr+nums[i];
            }
            if (max>curr) {
                max = max;
            }else {
                max=curr;
            }
        }
        return max;
    }
}